/**
 * @(#)SystemProcessReleaseNotesServiceImpl.java Sep 1, 2009
 *   
 * Copyright  (c) 2009-2010 Wilmar IT Service,  Inc.   
 * All  rights  reserved.   
 * TODO
 */

package com.wilmar.process.core.services.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.wilmar.process.core.services.api.ISystemProcessReleaseNotesService;
import com.wilmar.process.dao.api.IProcessReleaseNotesDAO;
import com.wilmar.process.entity.ProcessReleaseNotes;
import com.wilmar.process.entity.vo.ProcessReleaseNotesVO;
import com.wilmar.process.exception.ObjectNotFoundException;

/**
 * @author MaKuBEX Email:makubexnet@gmail.com
 * @version 1.0.0
 */
public class SystemProcessReleaseNotesServiceImpl implements
		ISystemProcessReleaseNotesService {

	private IProcessReleaseNotesDAO processReleaseNotesDAO;

	public IProcessReleaseNotesDAO getProcessReleaseNotesDAO() {
		return processReleaseNotesDAO;
	}

	/**
	 * @see com.wilmar.process.core.services.api.ISystemProcessReleaseNotesService#removeReleaseNotesByProcessDefinitionId(java.lang.String)
	 */
	public void removeReleaseNotesByProcessDefinitionId(
			String processDefinitionId) {
		ProcessReleaseNotes example = new ProcessReleaseNotes();
		example.setProcessDefinitionId(processDefinitionId);
		List<ProcessReleaseNotes> removingList = processReleaseNotesDAO
				.getListByExample(example);
		processReleaseNotesDAO.removeAll(removingList);
	}

	/**
	 * @see com.wilmar.process.core.services.api.ISystemProcessReleaseNotesService#saveReleaseNotes(com.wilmar.process.entity.ProcessReleaseNotes)
	 */
	public void saveReleaseNotes(ProcessReleaseNotes processReleaseNotes) {
		processReleaseNotesDAO.save(processReleaseNotes);
	}

	public void setProcessReleaseNotesDAO(
			IProcessReleaseNotesDAO processReleaseNotesDAO) {
		this.processReleaseNotesDAO = processReleaseNotesDAO;
	}

	/**
	 * @see com.wilmar.process.core.services.api.ISystemProcessReleaseNotesService#updateReleaseNotes(com.wilmar.process.entity.ProcessReleaseNotes)
	 */
	public void updateReleaseNotes(ProcessReleaseNotes processReleaseNotes) {
		processReleaseNotesDAO.update(processReleaseNotes);
	}

	/**
	 * @see com.wilmar.process.core.services.api.ISystemProcessReleaseNotesService#getDetail(java.lang.String)
	 */
	public ProcessReleaseNotes getDetailByProcessDefinitionId(
			String processDefinitionId) throws ObjectNotFoundException {
		ProcessReleaseNotes ex = new ProcessReleaseNotes();
		ex.setProcessDefinitionId(processDefinitionId);
		List<ProcessReleaseNotes> list = processReleaseNotesDAO
				.getListByExample(ex);
		if (list != null && list.size() > 0)
			return list.get(0);
		else
			throw new ObjectNotFoundException(
					"There is no process release note for this process definition, id is:"
							+ processDefinitionId);
	}

	/**
	 * @see com.wilmar.process.core.services.api.IBaseService#convertToVO(java.lang.Object)
	 */
	public ProcessReleaseNotesVO convertToVO(ProcessReleaseNotes entity) {
		ProcessReleaseNotesVO vo = new ProcessReleaseNotesVO(entity);
		return vo;
	}

	/**
	 * 
	 * @see com.wilmar.process.core.services.api.IBaseService#convertToVOList(java
	 *      .util.List)
	 */
	public List<ProcessReleaseNotesVO> convertToVOList(
			Collection<ProcessReleaseNotes> entityCollection) {
		List<ProcessReleaseNotesVO> voList = new ArrayList<ProcessReleaseNotesVO>(
				entityCollection.size());
		for (ProcessReleaseNotes notes : entityCollection) {
			voList.add(this.convertToVO(notes));
		}
		return voList;
	}

}
